package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.pro.ProcessStep;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pro.service.ProcessStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: YKYB
 * @Date: 2025/9/18 15:18
 * @Description:
 */

@RestController
@RequestMapping("/processStep")
public class ProcessStepController {
    @Autowired
    private ProcessStepService processStepService;

    @GetMapping("/page")
    public Result<PageInfo<ProcessStep>> page(
            @RequestParam(required = false) Long processId,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
//        if (processId == null) {
//            return Result.error("工序编号不能为空");
//        }
        return processStepService.selectPageByProcessId(processId, page, size);
    }

    @GetMapping("/get/{id}")
    public Result<ProcessStep> selecyById(@PathVariable Long id) {
        return processStepService.selectById(id);
    }

    @PostMapping("/add")
    public Result<ProcessStep> add(@RequestBody ProcessStep step) {
        return processStepService.addStep(step);
    }

    @PutMapping("/update")
    public Result<?> update(@RequestBody ProcessStep step) {
        return processStepService.updateStep(step);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        return processStepService.deleteStep(id);
    }
}


